from flask import request,Flask
import time,random
app = Flask(__name__) 

ap=None

@app.route('/', methods = ["POST"])
def post_data():
    global ap
    print(ap)
    c=0
    data=request.form
    if str(data["ht"])=="fond":
        
        while 1:
            if ap!=None:
                if ap[0]!=data["person"]:
                    print("self")
                    cd=ap
                    ap=[data["person"],data["wt"]]
                    time.sleep(1)
                    ap=None
                    return str(cd[0])+";"+str(cd[1])
                else:
                    time.sleep(0.5)
                    c+=1
                    if c>30:
                        ap=None
                        return "None;"+str(random.randint(0,2))
            else:
                ap=[data["person"],data["wt"]]
                time.sleep(0.5)
                c+=1
                if c>30:
                    ap=None
                    return "None;"+str(random.randint(0,2))
            
    return "font"
app.run(host="0.0.0.0",port="7002",debug=False)
    